﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Net.Configuration;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace CallCenter.Data.Utility
{
    public class EmailUtility
    {
        public static MailMessage SendMail(string subject, string body, string to, bool isbodyhtml = true)
        {
            var smtpSection = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");
            string username = smtpSection.Network.UserName;

            using (SmtpClient client = new SmtpClient())
            {
                
                MailMessage mailMessage = new MailMessage();
                mailMessage.To.Add(to);

                mailMessage.Subject = subject;
                mailMessage.Body = body;
                mailMessage.IsBodyHtml = isbodyhtml;
                //client.UseDefaultCredentials = false;

                //client.Credentials = smtpSection.Network.;
               //client.DeliveryMethod = SmtpDeliveryMethod.Network;
               // client.EnableSsl = true;

                client.Timeout = 30000;
                try
                {

                    client.Send(mailMessage);
                }
                catch (SmtpException e)
                {
                   
                }
  

                return mailMessage;
            }
        }
    }
}
